<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="scripts/jquery/jquery-1.7.1.js"></script>
<link href="style/authority/basic_layout.css" rel="stylesheet" type="text/css">
<link href="style/authority/common_style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
<link rel="stylesheet" type="text/css" href="style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>

<title>用户管理</title>
<script type="text/javascript">
	$(document).ready(function(){
		/** 新增   **/
	    $("#addBtn").fancybox({
	    	'href'  : 'house_edit.html',
	    	'width' : 733,
	        'height' : 530,
	        'type' : 'iframe',
	        'hideOnOverlayClick' : false,
	        'showCloseButton' : false,
	        'onClosed' : function() { 
	        	window.location.href = 'house_list.html';
	        }
	    });
		
	    /** 导入  **/
	    $("#importBtn").fancybox({
	    	'href'  : '/xngzf/archives/importFangyuan.action',
	    	'width' : 633,
	        'height' : 260,
	        'type' : 'iframe',
	        'hideOnOverlayClick' : false,
	        'showCloseButton' : false,
	        'onClosed' : function() { 
	        	window.location.href = 'house_list.html';
	        }
	    });
		
	    /**编辑   **/
	    $("a.edit").fancybox({
	    	'width' : 733,
	        'height' : 530,
	        'type' : 'iframe',
	        'hideOnOverlayClick' : false,
	        'showCloseButton' : false,
	        'onClosed' : function() { 
	        	window.location.href = 'house_list.html';
	        }
	    });
	});
	/** 用户角色   **/
	var userRole = '';

	/** 模糊查询来电用户  **/
	function search(){
		$("#submitForm").attr("action", "house_list.html?page=" + 1).submit();
	}

	/** 新增   **/
	function add(){
		$("#submitForm").attr("action", "/xngzf/archives/luruFangyuan.action").submit();	
	}
	 
	/** Excel导出  **/
	function exportExcel(){
		if( confirm('您确定要导出吗？') ){
			var fyXqCode = $("#fyXq").val();
			var fyXqName = $('#fyXq option:selected').text();
//	 		alert(fyXqCode);
			if(fyXqCode=="" || fyXqCode==null){
				$("#fyXqName").val("");
			}else{
//	 			alert(fyXqCode);
				$("#fyXqName").val(fyXqName);
			}
			$("#submitForm").attr("action", "/xngzf/archives/exportExcelFangyuan.action").submit();	
		}
	}
	
	/** 删除 **/
	function del(fyID){
		// 非空判断
		if(fyID == '') return;
		if(confirm("您确定要删除吗？")){
			$("#submitForm").attr("action", "/xngzf/archives/delFangyuan.action?fyID=" + fyID).submit();			
		}
	}
	
	/** 批量删除 **/
	function batchDel(){
		if($("input[name='IDCheck']:checked").size()<=0){
			art.dialog({icon:'error', title:'友情提示', drag:false, resize:false, content:'至少选择一条', ok:true,});
			return;
		}
		// 1）取出用户选中的checkbox放入字符串传给后台,form提交
		var allIDCheck = "";
		$("input[name='IDCheck']:checked").each(function(index, domEle){
			bjText = $(domEle).parent("td").parent("tr").last().children("td").last().prev().text();
// 			alert(bjText);
			// 用户选择的checkbox, 过滤掉“已审核”的，记住哦
			if($.trim(bjText)=="已审核"){
// 				$(domEle).removeAttr("checked");
				$(domEle).parent("td").parent("tr").css({color:"red"});
				$("#resultInfo").html("已审核的是不允许您删除的，请联系管理员删除！！！");
// 				return;
			}else{
				allIDCheck += $(domEle).val() + ",";
			}
		});
		// 截掉最后一个","
		if(allIDCheck.length>0) {
			allIDCheck = allIDCheck.substring(0, allIDCheck.length-1);
			// 赋给隐藏域
			$("#allIDCheck").val(allIDCheck);
			if(confirm("您确定要批量删除这些记录吗？")){
				// 提交form
				$("#submitForm").attr("action", "/xngzf/archives/batchDelFangyuan.action").submit();
			}
		}
	}

	/** 普通跳转 **/
	function jumpNormalPage(page){
		$("#submitForm").attr("action", "house_list.html?page=" + page).submit();
	}
	
	/** 输入页跳转 **/
	function jumpInputPage(totalPage){
		// 如果“跳转页数”不为空
		if($("#jumpNumTxt").val() != ''){
			var pageNum = parseInt($("#jumpNumTxt").val());
			// 如果跳转页数在不合理范围内，则置为1
			if(pageNum<1 | pageNum>totalPage){
				art.dialog({icon:'error', title:'友情提示', drag:false, resize:false, content:'请输入合适的页数，\n自动为您跳到首页', ok:true,});
				pageNum = 1;
			}
			$("#submitForm").attr("action", "house_list.html?page=" + pageNum).submit();
		}else{
			// “跳转页数”为空
			art.dialog({icon:'error', title:'友情提示', drag:false, resize:false, content:'请输入合适的页数，\n自动为您跳到首页', ok:true,});
			$("#submitForm").attr("action", "house_list.html?page=" + 1).submit();
		}
	}
	/*添加用户*/
	function addAdmin(){
		var aname;
		var apassword;
		var role;
		var rid;
		var cid;
		aname = $("#fyZldz1").val();
		apassword = $("#fyZldz2").val();
		role = $("#fyXq").val();
		if(role == "5"){
			role="管理员";
		}else{
			role="普通用户";
		}
		rid = $("#fyXq11").val();
		cid = $("#fyXq12").val();
		$.ajax({
			url:"admin.action?addAdmin",
		    data:"aname="+aname+"&apassword="+apassword+"&role="+role+"&rid="+rid+"&cid="+cid,
		    type:"POST",
		    datatype:"text",
		    error:function(){
		    	
		    },
		    success:function(data){
		    	if(data==1){
		    		alert("添加成功！");
		    	}else{
		    		alert("添加失败！");
		    	}
		    showAdmin();
		    },
		})
		alert(aname+"---"+apassword+"---"+role+"---"+rid+"---"+cid);
	}
	
	
	/*显示所有用户*/
	function fillData(data){
		$("#adminContent").html("");
		for (var key in data){
			
			$("#adminContent").html(
					$("#adminContent").html()+
					"<tr >"+"<td><input type=\"checkbox\" name=\"IDCheck\" value=\"14458579642011\" class=\"acb\" /></td>"+
					"<td class=\"td1j\">"+data[key].aname+"</td>"+
					"<td class=\"td1j\">"+data[key].apassword+"</td>"+
					"<td class=\"td1j\">"+data[key].role+"</td>"+
					"<td class=\"td1j\">"+data[key].region.rname+"</td>"+
					"<td class=\"td1j\">"+data[key].customer.cname+"</td>"+
					"<td>"+
// 					"<a href='admin_edit.html?fyID=14458579642011' class=\"edit\">编辑</a>"+
// 					"<a href='admin_edit.html?aid=1' class='edit'>编辑</a>"+
					"<a href=\"javascript:overlay('"+data[key].aid+"','"+data[key].aname+"','"+data[key].apassword+"','"+data[key].role+"','"+data[key].region.rid+"','"+data[key].customer.cid+"');\">编辑</a>"+
					"<a href=\"javascript:deleteAdmin("+data[key].aid+");\">删除</a>"+
					"</td>"+
					"</tr>"		
			);
		}
	}
	/*查询所有区域*/
	function allRegion(){
		//alert(2);
		$.ajax({
			url:"region.action?showRegion",
			data:"",
			type:"POST",
			datatype:"text",
			error:function(){
				
			},
			success:function(data){
				//alert(data);
					$("#fyXq11").html("");
					$("#regionxiugai").html("");
					$("#fyXq11").html("<option value=\"\" >--请选择--</option>");
					$("#regionxiugai").html("<option value=\"\" >--请选择--</option>");
				for(var key in data){
					$("#fyXq11").html($("#fyXq11").html()+"<option value=\""+data[key].rid+"\" >"+data[key].rname+"</option>");
					$("#regionxiugai").html($("#regionxiugai").html()+"<option value=\""+data[key].rid+"\" >"+data[key].rname+"</option>");
				};
			},
		})
	}
	/*查询所有客户*/
	function allCustomer(){
		$.ajax({
			url:"customer.action?showCustomer",
			data:"",
			type:"POST",
			datatype:"text",
			error:function(){
				
			},
			success:function(data){
					$("#fyXq12").html("");
					$("#customerxiugai").html("");
					$("#fyXq12").html("<option value=\"\" >--请选择--</option>");
					$("#customerxiugai").html("<option value=\"\" >--请选择--</option>");
				for(var key in data){
					$("#fyXq12").html($("#fyXq12").html()+"<option value=\""+data[key].cid+"\" >"+data[key].cname+"</option>");
					$("#customerxiugai").html($("#customerxiugai").html()+"<option value=\""+data[key].cid+"\" >"+data[key].cname+"</option>");
				};
			},
		})
	}
	/*删除*/
	function deleteAdmin(aid){
// 		alert(aid);
	if(confirm("确定删除么？")){
		$.ajax({
			url:"admin.action?deleteAdmin",
			data:"aid="+aid,
			type:"POST",
			datatype:"text",
			error:function(){
				
			},
			success:function(data){
				if(data == "1"){
					alert("删除成功！")
    				showAdmin();
				}else{
					alert("删除失败！");
				}
			},
		})
	   }
	}
	/*查询所有用户*/
	function showAdmin(){
// 		alert("zhognguo");
		$.ajax({
			url:"admin.action?showAdmin",
			data:"",
			type:"POST",
			datatype:"text",
			error:function(){
				alert("zhongguo!")
			},
			success:function(data){
				fillData(data);
				allRegion();
				allCustomer();
			},
		})
	}
</script>
<style>
	.alt td{ background:black !important;}
</style>
</head>
<body onload="showAdmin()">
	<form id="submitForm" name="submitForm" action="" method="post">
<!-- 	在进行编辑之前将aid存起来 -->
		<input type="hidden" name="allIDCheck" value="" id="allIDCheck"/>
		<input type="hidden" name="fangyuanEntity.fyXqName" value="" id="fyXqName"/>
		<div id="container">
			<div class="ui_content">
				<div class="ui_text_indent">
					<div id="box_border">
						<div id="box_top">添加用户</div>
						<div id="box_center">
							用户名&nbsp;
							<input type="text" id="fyZldz1" name="fangyuanEntity.fyZldz" class="ui_input_txt02" />
                          &nbsp; 密码&nbsp;
							<input type="text" id="fyZldz2" name="fangyuanEntity.fyZldz" value="" class="ui_input_txt02" />
                           
                           权限：
						    <select name="fangyuanEntity.fyXqCode" id="fyXq" class="ui_select01" onchange="getFyDhListByFyXqCode();">
                                <option value="" >--请选择--</option>
                                <option value="5">管理员</option>
                                <option value="6">普通用户</option>

                            </select>
						</div>
                        
						<div id="box_center1">
							所属区域：&nbsp;
						    <select name="fangyuanEntity.fyXqCode" id="fyXq11" class="ui_select01" onchange="getFyDhListByFyXqCode();">
                            </select>
                            所属客户：
						    <select name="fangyuanEntity.fyXqCode" id="fyXq12" class="ui_select01" onchange="getFyDhListByFyXqCode();">
                            </select>
                            
                            <div style="text-align:right">
                                <input type="button" value="添加" class="ui_input_btn01" onclick="addAdmin()"/>
                            </div>
                            
						</div>
                        
					</div>
				</div>
			</div>
			<div class="ui_content">
				<div class="ui_tb">
					<table class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
						<tr>
							<th width="30"><input type="checkbox" id="all" onclick="selectOrClearAllCheckbox(this);" />
							</th>
							<th>用户名</th>
							<th>密码</th>
                            <th>权限</th>
							<th>所属地区</th>
                            <th>所属客户</th>
							<th>操作</th>
                            
						</tr>
						<tbody id="adminContent">
						</tbody>
						
					</table>
				</div>
				<div class="ui_tb_h30">
					<div class="ui_flt" style="height: 30px; line-height: 30px;">
						共有
						<span class="ui_txt_bold04">90</span>
						条记录，当前第
						<span class="ui_txt_bold04">1
						/
						9</span>
						页
					</div>
					<div class="ui_frt">
						<!--    如果是第一页，则只显示下一页、尾页 -->
						
							<input type="button" value="首页" class="ui_input_btn01" />
							<input type="button" value="上一页" class="ui_input_btn01" />
							<input type="button" value="下一页" class="ui_input_btn01"
								onclick="" />
							<input type="button" value="尾页" class="ui_input_btn01"
								onclick="" />
						
						
						
						<!--     如果是最后一页，则只显示首页、上一页 -->
						
						转到第<input type="text" id="jumpNumTxt" class="ui_input_txt01" />页
							 <input type="button" class="ui_input_btn01" value="跳转" onclick="" />
					</div>
				</div>
			</div>
		</div>
	</form>

    
<!-- 打开模态框 -->
<a onclick="overlay()">模态框</a>
<!-- 打开模态框 END -->


<!-- 编辑模态框 -->
<div id="modal-overlay"> 
    <div class="modal-data">
    	<!-- 页首 -->
		<div id="nav_links">
			当前位置：基础数据&nbsp;>&nbsp;<span style="color: #1A5CC6;">用户域管理</span>
			<div id="page_close">
				<a href="javascript:parent.$.fancybox.close();">
					<img src="images/common/page_close.png" onclick="overlay()" width="20" height="20" style="vertical-align: text-top;"/>
				</a>
			</div>
		</div>
    	<!-- 页首 END -->
        <!-- 区域id -->
        <input style="visibility:hidden;" value="" id="xiugaiquyuaid"/>
        <!-- 页面内容 -->
        <table  cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
            <tr>
                <td class="ui_text_rt" width="110" >用户名称：</td>
                <td><input type="text" class="ui_input_txt02" id="aname"/></td>
            </tr>
            <tr>
                <td class="ui_text_rt" width="110" >密码：</td>
                <td><input type="text" class="ui_input_txt02" id="apassword"/></td>
            </tr>
            
            <tr>
                <td class="ui_text_rt" width="110">角色：</td>
                <td> 
                    <select class="ui_select01" onchange="getFyDhListByFyXqCode();" id="rolexiugai">
                        <option value="" >--请选择--</option>
                        <option value="5" >管理员</option>
                        <option value="6" >普通用户</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="ui_text_rt" width="110">所属地区：</td>
                <td> 
<!--                     <select class="ui_select01" onchange="getFyDhListByFyXqCode();" id="regionxiugai"> -->
                    <select class="ui_select01" id="regionxiugai">
                    </select>
                </td>
            </tr>
            <tr>
                <td class="ui_text_rt" width="110">所属客户：</td>
                <td> 
<!--                     <select class="ui_select01" onchange="getFyDhListByFyXqCode();" id="customerxiugai"> -->
                    <select class="ui_select01" id="customerxiugai">
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    &nbsp;<input type="submit" value="确定修改" class="ui_input_btn01" onclick="update() "/>
                    &nbsp;<input type="reset" value="取消" onclick="overlay()" class="ui_input_btn01"/>
                </td>
            </tr>
            
        </table>
        <!-- 页面内容 END -->
        <div style="position:absolute; left:900px; top:450px;" >
        </div>
    </div>
</div>

<a href="#" onclick="overlay(1)">显示模态对话框</a>
<style>/* 定义模态对话框外面的覆盖层样式 */
#modal-overlay {
	visibility: hidden;    
	position: absolute;   /* 使用绝对定位或固定定位  */
	left: 0px;    
	top: 0px;
	width:100%;
	height:100%;
	text-align:center;
	z-index: 1000;
	background-color: #333; 
	opacity:0.9;   /* 背景透明 */
}
/* 模态框样式 */
.modal-data{
	width:600px;
	height:300px;
	margin: 100px auto;
	background-color: rgba(255,255,255,1.00);
	border:1px solid #000;
	padding:15px;
	text-align:left;
	
}
</style>
<!-- onclick=overlay(data[key].rid， -->
<script>
function overlay(aid,aname,apassword,role,rid,cid){
// 	alert(aid+"---"+aname+"--"+apassword+"--"+role+"--"+rid+"--"+cid);
	$("#xiugaiquyuaid").val(aid);
    $("#aname").val(aname);
    $("#apassword").val(apassword);
    if(role == "管理员"){
    	role=5;
    }else{
    	role=6;
    }
    $("#rolexiugai").val(role);
    $("#regionxiugai").val(rid);
    $("#customerxiugai").val(cid);
    var e1 = document.getElementById('modal-overlay');
    e1.style.visibility = (e1.style.visibility == "visible")? "hidden" : "visible";
    alert(rid+rname);
}
/**更新操作**/
function update(){
	var aid = $("#xiugaiquyuaid").val();
	var aname = $("#aname").attr("value");
	var apassword = $("#apassword").attr("value");
	var role = $("#rolexiugai").val();
	if(role == 5){
		role = "管理员";
	}else{
		role = "普通用户";
	}
	var rid = $("#regionxiugai").attr("value");
	var cid = $("#customerxiugai").attr("value");
	alert(aid+"   "+aname+"   "+apassword+"   "+role+"   "+rid+"   "+cid);
    $.ajax({
    	url:"admin.action?updateAdmin",
    	data:{"aid":aid,"aname":aname,"apassword":apassword,"role":role,"rid":rid,"cid":cid},
    	type:"POST",
    	datatype:"text",
    	error:function(){
    		
    	},
    	success:function(data){
    		if(data==1){
				alert("修改成功！");
                var e1 = document.getElementById('modal-overlay');
                e1.style.visibility = (e1.style.visibility == "visible")? "hidden" : "visible";
                showAdmin();
				}else{
					alert("修改失败！");
				}
    		showRegion();
    	},
    })
}
</script>


</body>
</html>
